home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TIMING.SWG / 0018_Stop Watch Function.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  2KB  |  84 lines

  1. {
  2.  
  3. I am sure it is not the most elegant implementation. Except for the night
  4. of February 29th to March 1st, it should work fine. You might want to
  5. through out the escape and beep procedures. }
  6.  
  7.  
  8.  
  9. unit Time;  {JMR'91}    { Unit zur Bestimmung von Programmlaufzeiten }
  10.  
  11. interface
  12.  
  13.   uses DOS,Crt;
  14.  
  15.   procedure Start;
  16.   procedure Elapsed(var Hour,Minute,Second,HundSec:Word); 
  17.   function ElapsedStr:String;    { 'HH:MM:SS,HH' }
  18.   { Elapsed und ElapsedStr ermitteln die Zeit, die seit dem Aufruf von  }
  19.   { Start vergangen ist. Schaltjahre werden nicht berücksichtigt.  }
  20.   procedure beep;           { gibt kurzen Ton }
  21.   function escape:Boolean;  { true, wenn <Esc> gedrückt wurde (ReadKey) }
  22. {***************************************************************************}
  23.  
  24. implementation
  25.  
  26. var Y,Month,Day,DoW,Month0,Day0,Hour0,Minute0,Second0,HundSec0:Word;
  27.  
  28. procedure Start;
  29.   begin
  30.     GetTime(Hour0,Minute0,Second0,HundSec0);
  31.     GetDate(Y,Month0,Day0,DoW);
  32.   end;
  33.  
  34. procedure Elapsed;
  35.   begin
  36.     GetTime(Hour,Minute,Second,HundSec);
  37.     GetDate(Y,Month,Day,DoW);
  38.     HundSec:=HundSec-HundSec0;
  39.     if HundSec>99 then begin HundSec:=HundSec+100; dec(Second) end;
  40.     Second:=Second-Second0;
  41.     if Second>59 then begin Second:=Second+60; dec(Minute) end;
  42.     Minute:=Minute-Minute0;
  43.     if Minute>59 then begin Minute:=Minute+60; dec(Hour) end;
  44.     Hour:=Hour-Hour0;
  45.     Day:=Day-Day0;
  46.     if Day>30 then if Month in [1,3,5,7,8,10,12] then Day:=Day+31
  47.     else if Month<>2 then Day:=Day+30
  48.          else Day:=Day+28;
  49.     if Hour>23 then Hour:=Hour+24*Day;
  50.   end;
  51.  
  52. function ElapsedStr;
  53.   var Hour,Minute,Second,HundSec:Word;
  54.   function LeadingZero(w:Word):String;
  55.     var s:String;
  56.     begin
  57.       Str(w:0,s);
  58.       if Length(s)=1 then s:='0'+s;
  59.       LeadingZero:=s;
  60.     end;
  61.   begin
  62.     Elapsed(Hour,Minute,Second,HundSec);
  63.     ElapsedStr:=LeadingZero(Hour)+':'+LeadingZero(Minute)+':'
  64.         +LeadingZero(Second){+','+LeadingZero(HundSec)};
  65.   end;
  66.  
  67. procedure beep;
  68.   begin
  69.     sound(440);
  70.     delay(10);
  71.     nosound;
  72.   end;
  73.  
  74. function Escape;
  75.   var Taste:Char;
  76.   begin
  77.     if Keypressed then
  78.  if Ord(ReadKey)=27 then Escape:=true
  79.      else Escape:=false
  80.     else Escape:=false;
  81.   end;
  82.  
  83. end. { Unit Time }
  84.